cmake_minimum_required(VERSION 3.10)
project(TimeMachinePredict)

# 设置C++标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 启用优化
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
    add_compile_options(-O3 -march=native)
endif()

# 设置输出目录
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# 包含路径
include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}/inc
    ${CMAKE_SOURCE_DIR}/lib/inc
)

# 查找Eigen3
find_package(Eigen3 REQUIRED)
include_directories(${EIGEN3_INCLUDE_DIRS})

# 源文件列表 - 使用后缀匹配方式（关键修改）
file(GLOB SOURCES 
    src/*.cpp
    src/vector/*.cpp
    src/eigen/*.cpp
)

# 创建可执行文件
add_executable(${PROJECT_NAME} ${SOURCES})

# 链接依赖库
if(TARGET learn_deep_learning)
    # 当作为子项目构建时
    target_link_libraries(${PROJECT_NAME} 
        learn_deep_learning
        Eigen3::Eigen
        TBB::tbb
    )
else()
    # 独立构建时的备选方案
    find_library(LEARN_DEEP_LEARNING_LIB 
        NAMES learn_deep_learning
        HINTS ${CMAKE_SOURCE_DIR}/../lib
        REQUIRED
    )
    target_link_libraries(${PROJECT_NAME} 
        ${LEARN_DEEP_LEARNING_LIB}
        Eigen3::Eigen
        TBB::tbb
    )
endif()

# 数据文件处理
if(EXISTS ${CMAKE_SOURCE_DIR}/data/TimeMachine)
    # 创建目标数据目录
    file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/data/TimeMachine)
    
    # 复制整个数据目录（使用GLOB匹配数据文件）
    file(GLOB DATA_FILES ${CMAKE_SOURCE_DIR}/data/TimeMachine/*)
    file(COPY ${DATA_FILES} 
         DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/data/TimeMachine
    )
    
    # 安装数据文件
    install(DIRECTORY ${CMAKE_SOURCE_DIR}/data/TimeMachine/
            DESTINATION share/TimeMachinePredict/data
    )
endif()

# 安装规则
install(TARGETS ${PROJECT_NAME}
    RUNTIME DESTINATION bin
)

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/inc/
    DESTINATION include/TimeMachinePredict
    FILES_MATCHING 
    PATTERN "*.h"
    PATTERN "*.hpp"
)